package cn.fintecher.pangolin.service.dataimp.web;

import cn.fintecher.pangolin.common.model.UserModel;
import cn.fintecher.pangolin.service.dataimp.model.request.ApprovalExportRequest;
import cn.fintecher.pangolin.service.dataimp.model.request.ApprovalImportDataRequest;
import cn.fintecher.pangolin.service.dataimp.request.ExportPaymentCheck;
import cn.fintecher.pangolin.service.dataimp.service.ApprovalExportService;
import cn.fintecher.pangolin.service.dataimp.service.BaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author wangxiangdong
 * @Description 审批相关导入导出
 * @Date 2019/10/17 9:39
 **/
@RestController
@RequestMapping("/api/approvalExportManageController")
@Api(value = "审批相关导入导出", description = "审批相关导入导出")
public class ApprovalExportManageController {


    @Autowired
    private ApprovalExportService approvalExportService;

    @Autowired
    private BaseService baseService;

    @ApiOperation(value = "协催管理导出", notes = "协催管理导出")
    @PostMapping("/approvalMessageExport")
    public ResponseEntity approvalMessageExport(@RequestBody ApprovalExportRequest request, @RequestHeader(value = "X-UserToken") String token){
        approvalExportService.getExportTitle(request, token);
        return ResponseEntity.ok().build();
    }

    @PostMapping("/approvalByImportData")
    @ApiOperation(value = "导入审批", notes = "导入审批")
    public ResponseEntity approvalByImportData(@Valid @RequestBody ApprovalImportDataRequest request, @RequestHeader(value = "X-UserToken") String token) {
        UserModel userModel = baseService.getUserByToken(token);
        approvalExportService.approvalByImportData(request,userModel);
        return ResponseEntity.ok().build();
    }

    @ApiOperation(value = "查账申请导出", notes = "查账申请导出")
    @PostMapping("/exportPaymentCheck")
    public ResponseEntity exportPaymentCheck(@RequestBody ExportPaymentCheck exportPaymentCheck, @RequestHeader(value = "X-UserToken") String token){
        approvalExportService.getExportPaymentCheckTitle(exportPaymentCheck, token);
        return ResponseEntity.ok().build();
    }

    @PutMapping("/importPaymentCheck/{fileId}")
    @ApiOperation(value = "回复导入", notes = "回复导入")
    public ResponseEntity importPaymentCheck(@PathVariable String fileId,@RequestHeader(value = "X-UserToken") String token) {
        approvalExportService.importPaymentCheck(fileId, token);
        return ResponseEntity.ok().build();
    }
}
